﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

namespace Maticsoft.Web
{
    public partial class Index : System.Web.UI.Page
    {
        Maticsoft.BLL.newsInfo nm = new BLL.newsInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                HyperLink1.NavigateUrl = "study.aspx?type=" + Server.UrlEncode("党政机关").ToString();
                HyperLink2.NavigateUrl = "ListMN.aspx?type=" + Server.UrlEncode("党政机关").ToString();
                Bind();
            }
        }

        private void Bind() 
        {
            //List<Maticsoft.Model.newsInfo> nl_t1 = nm.GetModelList(" newsType='党内法规制度' ");
            //List<Maticsoft.Model.newsInfo> nl_t2 = nm.GetModelList(" newsType='国家法律法规' ");
            //List<Maticsoft.Model.newsInfo> nl_t3 = nm.GetModelList(" newsType='省内法规制度' ");
            //List<Maticsoft.Model.newsInfo> nl_t4 = nm.GetModelList(" newsType='领导重要讲话' ");
            List<Maticsoft.Model.newsInfo> nl_t5 = nm.GetModelList(" newsType='通知公告' ");
            List<Maticsoft.Model.newsInfo> nl_t6 = nm.GetModelList(" newsType='资料库' and parentId = 0 ");

            #region t1
            //StringBuilder st1 = new StringBuilder();

            //if (nl_t1.Count > 10)
            //{
            //    for (int i = 0; i < 10; i++)
            //    {
            //        StrAppend(nl_t1, st1, i);
            //    }
            //}
            //else
            //{
            //    for (int i = 0; i < nl_t1.Count; i++)
            //    {
            //        StrAppend(nl_t1, st1, i);
            //    }
            //}

            //this.lti_t1.Text = st1.ToString();
            #endregion

            #region t2
            //StringBuilder st2 = new StringBuilder();

            //if (nl_t2.Count > 10)
            //{
            //    for (int i = 0; i < 10; i++)
            //    {
            //        StrAppend(nl_t2, st2, i);
            //    }
            //}
            //else
            //{
            //    for (int i = 0; i < nl_t2.Count; i++)
            //    {
            //        StrAppend(nl_t2, st2, i);
            //    }
            //}

            //this.lti_t2.Text = st2.ToString();
            #endregion

            #region t3
            //StringBuilder st3 = new StringBuilder();

            //if (nl_t3.Count > 10)
            //{
            //    for (int i = 0; i < 10; i++)
            //    {
            //        StrAppend(nl_t3, st3, i);
            //    }
            //}
            //else
            //{
            //    for (int i = 0; i < nl_t3.Count; i++)
            //    {
            //        StrAppend(nl_t3, st3, i);
            //    }
            //}

            //this.lti_t3.Text = st3.ToString();
            #endregion

            #region t4
            //StringBuilder st4 = new StringBuilder();

            //if (nl_t4.Count > 10)
            //{
            //    for (int i = 0; i < 10; i++)
            //    {
            //        StrAppend(nl_t4, st4, i);
            //    }
            //}
            //else
            //{
            //    for (int i = 0; i < nl_t4.Count; i++)
            //    {
            //        StrAppend(nl_t4, st4, i);
            //    }
            //}

            //this.lti_t4.Text = st4.ToString();
            #endregion

            #region t5
            StringBuilder st5 = new StringBuilder();

            if (nl_t5.Count > 10)
            {
                for (int i = 0; i < 10; i++)
                {
                    StrAppendNotice(nl_t5, st5, i);
                }
            }
            else
            {
                for (int i = 0; i < nl_t5.Count; i++)
                {
                    StrAppendNotice(nl_t5, st5, i);
                }
            }

            this.lti_t5.Text = st5.ToString();
            #endregion

            #region t6
            StringBuilder st6 = new StringBuilder();

            if (nl_t6.Count > 10)
            {
                for (int i = 0; i < 10; i++)
                {
                    StrAppendToZLK(nl_t6, st6, i);
                }
            }
            else
            {
                for (int i = 0; i < nl_t6.Count; i++)
                {
                    StrAppendToZLK(nl_t6, st6, i);
                }
            }

            this.lti_t1.Text = st6.ToString();
            #endregion

        }


        private static void StrAppendToZLK(List<Maticsoft.Model.newsInfo> nl_t1, StringBuilder str, int i)
        {
            str.Append(" <div class='item'> ");
            str.Append("  <a href='ListF.aspx?a=");
            str.Append(nl_t1[i].newsId);
            str.Append(" ' title='");
            str.Append(nl_t1[i].newsTitle);
            str.Append(" '>  ");
            str.Append(nl_t1[i].newsTitle);
            str.Append("</a></div>");

        }
        private static void StrAppend(List<Maticsoft.Model.newsInfo> nl_t1, StringBuilder str, int i)
        {
            str.Append(" <div class='item'> ");
            str.Append("  <a href='read.aspx?a=");
            str.Append(nl_t1[i].newsId);
            str.Append(" ' title='");
            str.Append(nl_t1[i].newsTitle);
            str.Append(" '>  ");
            str.Append(nl_t1[i].newsTitle);
            str.Append("</a></div>");

        }

        private static void StrAppendNotice(List<Maticsoft.Model.newsInfo> nl_t1, StringBuilder str, int i)
        {
            str.Append(" <div class='item'> ");
            str.Append("  <a href='read.aspx?a=");
            str.Append(nl_t1[i].newsId);
            str.Append(" ' title='");
            str.Append(nl_t1[i].newsTitle);
            str.Append(" '>  ");
            str.Append(nl_t1[i].newsTitle);
            str.Append("</a>");
            str.Append("(");
            str.Append(nl_t1[i].newsPubTime.Value.ToShortDateString());
            str.Append(")");
            str.Append("</div>");

        }

        protected void btn_login_Click(object sender, EventArgs e)
        {
            string pass = this.txt_kh.Text;
            string name = this.txt_name.Text;

            List<Maticsoft.Model.studentInfo> lu = new Maticsoft.BLL.studentInfo().GetModelList(" and stuname='" + name + "' and stunum ='" + pass + "' ");

            if (lu.Count > 0)
            {
                Session["login"] = lu[0];
                Response.Redirect("stu/Frame.aspx");
            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this.Page, "用户名密码不对！");
            }
        }

        //注册
        protected void btn_reg_Click(object sender, EventArgs e)
        {
            List<Maticsoft.Model.setUpInfo> sl = new Maticsoft.BLL.setUpInfo().GetModelList("");

            if (System.DateTime.Now <= sl[0].endTime && DateTime.Now >= sl[0].startTime)
            {
                Response.Redirect("~/stu/stuReg.aspx");
            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this.Page,"注册时间尚未开启！");
            }
        }
    }
}